﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;


namespace lcmyjobs.Web.enprise
{
    public partial class ListShowUser : BasePage
    {
        int  salaryymin = 0,salaryymax = 0, edu = 0, exp = 0, lan = 0, level = 0, count = 0,amin=0,amax=0,expmin=0,expmax=-1; 
        string jobs, area, trade,  huji, keys;
        lcmyjobs.BLL.user_basic bub = new BLL.user_basic();
        lcmyjobs.BLL.news bn = new BLL.news();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Application["webname"] != null)
                {
                    this.Title = string.Format("单位管理中心 简历搜索  {0}", Application["webname"].ToString());
                }
                if (Session["enterprise_name"] != null)
                {
                    this.lbl_title.Text = " " + Session["enterprise_name"].ToString();
                }
                if (Session["enterprise_bid"] != null)
                {
                    if (PreviousPage != null && PreviousPage.IsCrossPagePostBack && PreviousPage.IsValid)
                    {                       
                        jobs = ((TextBox)PreviousPage.FindControl("txtjob")).Text.Trim();
                        area = ((TextBox)PreviousPage.FindControl("txtarea")).Text.Trim();
                        trade = ((TextBox)PreviousPage.FindControl("txttrade")).Text.Trim();
                        huji = ((TextBox)PreviousPage.FindControl("txthuji")).Text.Trim(); 
                        string t=((TextBox)PreviousPage.FindControl("txtYmin")).Text.Trim();
                        if(t!="")
                        salaryymin = int.Parse(t);
                        t = ((TextBox)PreviousPage.FindControl("txtYmax")).Text.Trim();
                        if (t != "")
                            salaryymax = int.Parse(t);
                        t = ((TextBox)PreviousPage.FindControl("txtAmin")).Text.Trim();
                        if (t != "")
                            amin = int.Parse(t);
                        t = ((TextBox)PreviousPage.FindControl("txtAmax")).Text.Trim();
                        if (t != "")
                            amax = int.Parse(t);
                        edu = int.Parse(((DropDownList)PreviousPage.FindControl("ddledu")).SelectedValue.ToString());

                        exp = int.Parse(((DropDownList)PreviousPage.FindControl("ddlExp")).SelectedValue.ToString());
                        if (exp == 2)
                        { expmax = 0; }
                        else if (exp == 3)
                        { expmax = 3; }
                        else if (exp == 4)
                        { expmin = 3; expmax =100; }
                        else if (exp == 5)
                        { expmin = 5; expmax = 100; }
                        else if (exp == 6)
                        { expmin = 10; expmax = 100; }
                        else if (exp == 7)
                        { expmin = 15; expmax = 100; }
                        else if (exp == 8)
                        { expmin = 20; expmax = 100; }
                        else if (exp == 9)
                        { expmin = 25; expmax = 100; }
                        lan = int.Parse(((System.Web.UI.HtmlControls.HtmlSelect)PreviousPage.FindControl("selange")).Value.ToString());
                        level = int.Parse(((System.Web.UI.HtmlControls.HtmlSelect)PreviousPage.FindControl("selevel")).Value.ToString());
                       
                        keys = ((TextBox)PreviousPage.FindControl("txtKeyword")).Text.Trim();

                        lcmyjobs.Model.searchCondition sc = new Model.searchCondition();                       
                        sc.jobs = jobs;
                        sc.area = area;
                        sc.trade = trade;                       
                        sc.edu = edu;
                        sc.agemin = amin;
                        sc.agemax = amax;
                        sc.salaryymin = salaryymin;
                        sc.salaryymax = salaryymax;
                        sc.huji = huji;                        
                        sc.exp = exp;                        
                        sc.lan = lan;
                        sc.level = level; 
                        if(keys!="")
                        sc.keyword = keys;
                        sc.expmin = expmin;
                        sc.expmax = expmax;
                        Session["user_sc"] = sc;
                        getdate(1, AspNetPager1.PageSize, sc);
                    }
                    else if (Session["searchCondition"] != null)
                    {
                        lcmyjobs.Model.searchCondition sc = Session["searchCondition"] as lcmyjobs.Model.searchCondition;
                        //huji = sc.huji;
                        //salaryymin = sc.salaryymin;
                        //salaryymax = sc.salaryymax;
                        //amax = sc.agemax;
                        //amin = sc.agemin;
                        //edu = sc.edu;                        
                        //exp = sc.exp;
                        //lan = sc.lan;
                        //level = sc.level;
                        //count = sc.count;
                        //jobs = sc.jobs;
                        //area = sc.area;
                        //trade = sc.trade; 
                        //keys = sc.keyword;

                        getdate(1, AspNetPager1.PageSize, sc);

                        Session.Remove("searchCondition");
                    }
                    else
                    {
                        Response.Redirect("SearchUser.html");
                    }
                }
                else
                {
                    Maticsoft.Common.MessageBox.ShowAndRedirect(this, "请先登陆！", "EnterpriseLogin.html");
                }

            }
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            if (Session["user_sc"] != null)
            {
                getdate(AspNetPager1.StartRecordIndex, AspNetPager1.EndRecordIndex, (lcmyjobs.Model.searchCondition)Session["user_sc"]);
            }
        }

        protected void getdate(int start, int endindex, lcmyjobs.Model.searchCondition sc)
        {
            SqlParameter[] parameters = {			 
			 			 new SqlParameter("@job_name1", SqlDbType.NVarChar,20),
                          new SqlParameter("@job_name2", SqlDbType.NVarChar,20),
                          new SqlParameter("@job_name3", SqlDbType.NVarChar,20),                                                  
                          new SqlParameter("@edu", SqlDbType.Int,4),
                          new SqlParameter("@expmin", SqlDbType.Int,4),
                          new SqlParameter("@expmax", SqlDbType.Int,4), 
                          new SqlParameter("@salaryymin", SqlDbType.Int,4),
                          new SqlParameter("@salaryymax", SqlDbType.Int,4),   
                          new SqlParameter("@agemin", SqlDbType.Int,4),
                          new SqlParameter("@agemax", SqlDbType.Int,4),   
                         new SqlParameter("@areas1", SqlDbType.NVarChar,20), 
			 			 new SqlParameter("@areas2", SqlDbType.NVarChar,20), 
			 			 new SqlParameter("@areas3", SqlDbType.NVarChar,20), 
			 			 new SqlParameter("@trades1", SqlDbType.NVarChar,20), 
			 			 new SqlParameter("@trades2", SqlDbType.NVarChar,20), 
			 			 new SqlParameter("@trades3", SqlDbType.NVarChar,20),
                         new SqlParameter("@huji", SqlDbType.NVarChar,20),
                           new SqlParameter("@lan", SqlDbType.Int,4), 
			 			 new SqlParameter("@level", SqlDbType.Int,4), 
			 			 new SqlParameter("@startIndex", SqlDbType.Int,4), 
			 			 new SqlParameter("@endIndex", SqlDbType.Int,4),
			 			new SqlParameter("@keyword",SqlDbType.NVarChar,20),  
			 			 new SqlParameter("@count", SqlDbType.Int,4) 
			 			 
			 			 };
            string[] a;
            if (sc.jobs != "")
            {
                a = sc.jobs.Split(',');
                if (a.Length > 0)
                    parameters[0].Value = a[0];
                if (a.Length > 1)
                    parameters[1].Value = a[1];
                if (a.Length > 2)
                    parameters[2].Value = a[2];
            }
            parameters[3].Value = sc.edu;
            parameters[4].Value = sc.expmin;
            parameters[5].Value = sc.expmax;
            parameters[6].Value = sc.salaryymin;
            parameters[7].Value = sc.salaryymax;
            parameters[8].Value = sc.agemin;
            parameters[9].Value = sc.agemax;          
            if (sc.area != "")
            {
                a = sc.area.Split(',');
                if (a.Length > 0)
                    parameters[10].Value = a[0];
                if (a.Length > 1)
                    parameters[11].Value = a[1];
                if (a.Length > 2)
                    parameters[12].Value = a[2];
            }
            if (sc.trade != "")
            {
                a = sc.trade.Split(',');
                if (a.Length > 0)
                    parameters[13].Value = a[0];
                if (a.Length > 1)
                    parameters[14].Value = a[1];
                if (a.Length > 2)
                    parameters[15].Value = a[2];
            }
            parameters[16].Value = sc.huji;
            parameters[17].Value = sc.lan;
            parameters[18].Value = sc.level;
            parameters[19].Value = start;
            parameters[20].Value = endindex;
            parameters[21].Value = sc.keyword;
            parameters[22].Direction = ParameterDirection.Output;
            DataSet ds = bub.PageUserSearch(parameters,3);

            if (ds.Tables[0].Rows.Count > 0)
            {
                AspNetPager1.RecordCount = int.Parse(parameters[22].Value.ToString());
                GridView1.DataSource = ds.Tables[0];
                GridView1.DataBind();
                this.pnl_no.Visible = false;
                this.pnl_yes.Visible = true;
            }
            else
            {
                this.pnl_no.Visible = true;
                this.pnl_yes.Visible = false;
            }


        }
    }
}